package com.libgdxbar.pvzlikegame.systems;

import com.badlogic.gdx.utils.Array;
import com.libgdxbar.pvzlikegame.entities.Entity;
import com.libgdxbar.pvzlikegame.entities.EntitySystem;

import org.libgdxbar.projects.interfaces.ILooper;

public class UpdateSystem extends EntitySystem {

	private final Array<ILooper> loopers = new Array<>();

	@Override
	public void onEntityAdded(Entity entity) {
		if (entity instanceof ILooper) {
			ILooper looper = (ILooper) entity;
			loopers.add(looper);
		}
	}

	@Override
	public void onEntityRemoved(Entity entity) {
		if (entity instanceof ILooper) {
			ILooper looper = (ILooper) entity;
			loopers.removeValue(looper, true);
		}
	}

	@Override
	public void run(float delta) {
		for (ILooper looper : loopers) {
			looper.run(delta);
		}
	}

}
